#include "view_time_2.h"
#include "view_time_2.inc"
#include "view_time_0.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "view_common.h"
#include "app_trace.h"
#include "view_times.h"
#include "view_time_1.h"
#define LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)

static void show_time_2_steps(void)
{
    disp_draw_user_image_ignore_color(136, 201, RGB565_COLOR_BLACK, img_time_1_steps);
    int steps = disp_ctrl.com_data.i_temp[11];
    disp_draw_user_image_num(158, 204, steps, 11, img_time_0_num_TAB);
}
static void show_time_2_times(void)
{
    //表针
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_refresh_time = 1000;
        disp_ctrl.com_data.i_temp[22] = (RTCGetSeconds() % 60) * 6;
        uint16_t temp16 = get_present_day_minute();
        disp_ctrl.com_data.i_temp[23] = (temp16 / 2) / 6 * 6 % 360; //时针的角度
        disp_ctrl.com_data.i_temp[24] = (temp16 * 6) / 6 * 6 % 360; //分针的角度
    }
    disp_draw_img_rotate(gImage_3402_hourhand, 0, 45, (125 << 16) | 116, disp_ctrl.com_data.i_temp[23]);   //-3
    disp_draw_img_rotate(gImage_3403_minutehand, 0, 77, (125 << 16) | 116, disp_ctrl.com_data.i_temp[24]); //-7
    disp_draw_img_rotate(gImage_3404_secondhand2, 0, 83, (125 << 16) | 116, disp_ctrl.com_data.i_temp[22]);
    disp_draw_user_image_ignore_color(117, 108, RGB565_COLOR_BLACK, img_time_2_center);
}
static void show_time_2_month(void)
{
    uint8_t const img_time_2_month_TAB[] = {
        FILE_IMG_3101_jan_16_55, /* 10 */
        FILE_IMG_3102_feb_16_55, /* 11 */
        FILE_IMG_3103_mar_16_55, /* 12 */
        FILE_IMG_3104_apr_16_55, /* 13 */
        FILE_IMG_3105_may_16_55, /* 14 */
        FILE_IMG_3106_jun_16_55, /* 15 */
        FILE_IMG_3107_jul_16_55, /* 16 */
        FILE_IMG_3108_aug_16_55, /* 17 */
        FILE_IMG_3109_sep_16_55, /* 18 */
        FILE_IMG_3110_otc_16_55, /* 19 */
        FILE_IMG_3111_nov_16_55, /* 20 */
        FILE_IMG_3112_dec_16_55, /* 21 */
    };
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, 16, 55, img_time_2_month_TAB[disp_ctrl.com_data.i_temp[1] - 1]);
}

static void show_time_2_weeks(void)
{
    uint8_t const img_time_2_week_TAB[] = {
        FILE_IMG_3201_mon_16_124, /* 22 */
        FILE_IMG_3202_tue_16_124, /* 23 */
        FILE_IMG_3203_wed_16_124, /* 24 */
        FILE_IMG_3204_thu_16_124, /* 25 */
        FILE_IMG_3205_fri_16_124, /* 26 */
        FILE_IMG_3206_sat_16_124, /* 27 */
        FILE_IMG_3207_sun_16_124, /* 28 */
    };

    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, 16, 124, img_time_2_week_TAB[disp_ctrl.com_data.i_temp[5] - 1]);
}

static void show_time_2_days(void)
{
    uint8_t const img_time_2_date_TAB[] = {
        FILE_IMG_3300_date_0_122_54, /* 29 */
        FILE_IMG_3301_date_1_122_54, /* 30 */
        FILE_IMG_3302_date_2_122_54, /* 31 */
        FILE_IMG_3303_date_3_122_54, /* 32 */
        FILE_IMG_3304_date_4_122_54, /* 33 */
        FILE_IMG_3305_date_5_122_54, /* 34 */
        FILE_IMG_3306_date_6_122_54, /* 35 */
        FILE_IMG_3307_date_7_122_54, /* 36 */
        FILE_IMG_3308_date_8_122_54, /* 37 */
        FILE_IMG_3309_date_9_122_54, /* 38 */
    };
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, 122, 54, img_time_2_date_TAB[disp_ctrl.com_data.i_temp[2] / 10]);
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, 182, 54, img_time_2_date_TAB[disp_ctrl.com_data.i_temp[2] % 10]);
}
void view_time_2_display(void)
{
    show_time_0_ble();
    show_time_0_battery(disp_ctrl.com_data.i_temp[7], disp_ctrl.com_data.i_temp[8]);
    show_time_2_steps();
    show_time_2_month();
    show_time_2_weeks();
    show_time_2_days();
    show_time_2_times();
}
